package NewCalander;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class NewCalander {

	/**
	 * @param args
	 * @throws FileNotFoundException
	 */
	public static void main(String[] args) throws FileNotFoundException {
		String file = "src/NewCalander/A-small-attempt1.in";
		//String file = "src/NewCalander/A-large-practice.in";
		// String file = "src/NewCalander/test.txt";
		Scanner sc = new Scanner(new File(file));

		int nSets;
		nSets = sc.nextInt();
		sc.nextLine(); // go next line

		long totMonth, daysPerMonth, daysPerWeek; // for large input, choose long

		for (int i = 1; i <= nSets; i++) {
			totMonth = sc.nextLong();
			daysPerMonth = sc.nextLong();
			daysPerWeek = sc.nextLong();

			long a = fast(totMonth, daysPerMonth, daysPerWeek);
			//System.out.println("Case #" + i + ": " + a);
			long b = naive(totMonth, daysPerMonth, daysPerWeek);
			if (a != b) {
				System.out.println("Case #" + i + ": " + a + " " + b);
			}
			
		}
		sc.close();
	}

	static long fast(long totMonth, long daysPerMonth, long daysPerWeek) {
		long totLine = 0;

		if (daysPerMonth > daysPerWeek) {
			// always make daysPerMonth smaller than daysPerWeek
			totLine = (daysPerMonth / daysPerWeek) * totMonth;
			daysPerMonth = daysPerMonth % daysPerWeek;
		}

		if (daysPerMonth != 0) {
			totLine += totMonth;
			if (totMonth * daysPerMonth > daysPerWeek && daysPerWeek % daysPerMonth != 0) {
				// if there is more than daysPerweek days, then it means that one of daysPerMonth has two week-line.
				// and also daysPerWeek is not multiplied by daysPerMonth.
				// it means that there is no two week-line.
				totLine += getCycle(totMonth, daysPerMonth, daysPerWeek);
			}
		}

		return totLine;
	}

	/*
	 * if daysPerWeek is not multiplied by daysPerMonth, then there is remainder.
	 * if remainder is smaller than daysPerMonth, then it makes 2 line.
	 */
	static long getCycle(long totMonth, long daysPerMonth, long daysPerWeek) {
		
		long diff = daysPerWeek - daysPerMonth;
		
		// first remainder, it is empty.
		long remainder = daysPerWeek; 
		
		// for store accumulated number of lines
		ArrayList<Integer> al = new ArrayList<Integer>();
		
		int addedLines = 0;
		
		// always first line do not need additional line.
		al.add(0);
		remainder -= daysPerMonth;
		
		while (remainder != 0 && al.size() <= totMonth) {
			if (remainder < daysPerMonth) {
				// add additional line
				al.add(++addedLines);
			} else {
				al.add(addedLines);
			}
			
			if (remainder >= daysPerMonth) {
				// there is room to add daysPerMonth.
				remainder -= daysPerMonth;
			} else {
				// 2 line occurs.
				remainder += diff;
			}
		}
		
		// total cycle
		long cycle = totMonth / al.size();
		
		// remainder's index
		int idx = (int) (totMonth % al.size()) - 1;
		
		if (idx < 0) {
			idx = 0;
		}
		
		return al.get(idx) + (cycle * al.get(al.size()-1));
	}

	static long naive(long totMonth, long daysPerMonth, long daysPerWeek) {
		long remaining = 0; // remaining days of previous month
		long totLine = 0;
		remaining = 0;
		long q, r;
		for (int j = 0; j < totMonth; j++) {
			q = (daysPerMonth + remaining) / daysPerWeek;
			r = (daysPerMonth + remaining) % daysPerWeek;

			totLine = totLine + q;
			remaining = r;
			if (r != 0) {
				totLine++;
			}
		}
		return totLine;
	}
}
